<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
    mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
    components: {},
    data() {
        return {
            appWindow: window,
            popoverVisible: false,
            searchValue: "",
            form: {
                // 系统选择物流id
                companyId: "",
                // 数据类型 1选择系统 2自定义新增
                opType: 1,
                // 自定义新增名称
                companyName: "",
                // 自定义新增网址
                website: "",
            },
            logisticsOptions: [],
            logisticsFilter: [],
            // 页面接口地址
            apiUrl: {
                create: "mall-site-portal/logistics-company-setting/create",
                update: "mall-site-portal/logistics-company-setting/update",
                detail: "mall-site-portal/logistics-company-setting/getItem",
            },
        };
    },
    methods: {
        // 添加
        addValue() {
            this.form.companyId = "";
            this.form.companyName = this.searchValue;
            this.form.opType = 2;
            this.popoverVisible = false;
            this.mixinEdit_formValidate("editForm");
        },
        // 过滤查询
        filter() {
            let _list = [];
            this.logisticsOptions.forEach((item) => {
                if (item.companyName.indexOf(this.searchValue) >= 0) {
                    _list.push(item);
                }
            });
            this.logisticsFilter = _list;
        },
        // 选择
        selectItem(item_) {
            this.form.companyId = item_.id;
            this.form.companyName = item_.companyName;
            this.form.opType = 1;
            this.popoverVisible = false;
            this.mixinEdit_formValidate("editForm");
        },
        // 初始化
        async init() {
            // 初始化数据
            await this.mixinEdit_editBoxInit({
                model: "form",
                id: this.id,
                onInit: async () => {
                    // 数据源 物流列表
                    this.logisticsOptions = await this.$vFN.Tools.getSelectListSource(
                        {
                            url:
                                "mall-site-portal/logistics-company-setting/getLogisticsCompanyLst",
                            format: false,
                        },
                        window
                    );
                    this.filter();

                    return true;
                },
            });
        },
    },
    mounted() {
        this.init();
    },
    activated() {},
};
</script>